﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace TestMultiThreading
{
    /// <summary>
    /// Interaction logic for MultiThreadingWithSocket.xaml
    /// </summary>
    public partial class MultiThreadingWithSocket : Window
    {
        private static TextBox myResult;
        private delegate void AddTextDelegate(string test);
        public MultiThreadingWithSocket()
        {
            InitializeComponent();
            this.AddChild(myResult);
            RefreshInformationOfThreading();



        }

        private void RefreshInformationOfThreading()
        {
            int minWorker, minIOC;
            ThreadPool.GetMinThreads(out minWorker, out minIOC);
            txtNbMinThread.Text = minWorker.ToString();
            txtNbMinIdleAsyncThread.Text = minIOC.ToString();
            
            int maxWorker, maxIOC;
            ThreadPool.GetMaxThreads(out maxWorker, out maxIOC);
            txtNbMaxThread.Text = maxWorker.ToString();
            txtNbMaxIdleAsyncThread.Text = maxIOC.ToString();

            int AvailableWorker, availableIOC;
            ThreadPool.GetAvailableThreads(out AvailableWorker, out availableIOC);
            txtNbAvailableThread.Text = AvailableWorker.ToString();
            txtNbAvailableIdleAsyncThread.Text = availableIOC.ToString();
            Demo();


        }

 private static void DoWork()
   {
              int bob = 0;
            bob = 2;

      }


 public static void Demo()
 {
     //myResult = outputBlock;
     //myResult.Text = "Click here to start a background task.\r\n";

     //// Set up an event handler to start a task when the TextBlock 
     //// is clicked.
     //myResult.MouseLeftButtonDown += HandleMouseUp;

     Thread bob = new Thread(MultiThreadingWithSocket.DoWork);
 }

        public static void Demo(System.Windows.Controls.TextBox outputBlock)
        {
            //myResult = outputBlock;
            //myResult.Text = "Click here to start a background task.\r\n";

            //// Set up an event handler to start a task when the TextBlock 
            //// is clicked.
            //myResult.MouseLeftButtonDown += HandleMouseUp;

                             Thread bob = new Thread(MultiThreadingWithSocket.DoWork);
                             bob.Start();
        }

        private static void HandleMouseUp(object sender, MouseButtonEventArgs e)
        {

           // ThreadPool.QueueUserWorkItem(AppendTextTask);
            int bob = 0;
            bob = 2;


        }

        //private static void AppendTextTask(object stateInfo)
        //{
        //    myResult.Dispatcher.BeginInvoke(AddTextDelegate("Allo"));
            
        //}

        private void btnStartTest_Click(object sender, RoutedEventArgs e)
        {
           
           
        }



private static void test()
{
 	throw new NotImplementedException();
}
    }
}

